﻿Imports AvraamApplication
Imports WindowsControlLibrary1
Imports ProiontaUserControl
Imports AgoresUserControl
Imports PoliseisUserControl
Imports EpixeirisiUserControl

Public Class Form1

    Dim _imgHitArea As Point = New Point(13, 2)
    Dim _imageLocation As Point = New Point(15, 5)
    Dim file As System.IO.FileStream = System.IO.File.Create(Application.StartupPath & _
                                "\keppetairia.txt")
    Private Sub closestream()
        file.Close()
    End Sub


    Private Sub setaitaria(ByRef etairia As String)
        Try
            closestream()
        Catch ex As Exception
        End Try

        Try
            My.Computer.FileSystem.WriteAllText(Application.StartupPath & _
                                        "\keppetairia.txt", _
                                   etairiesComboBox.Text, True)
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try


    End Sub

    Private Function keepetaira() As String
        Try
            closestream()
        Catch ex As Exception
        End Try
        Dim fileReader As String = "none"
        Try
            fileReader = My.Computer.FileSystem.ReadAllText(Application.StartupPath & _
                                            "\keppetairia.txt")
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        Return fileReader
    End Function

    Public Sub New()
        closestream()

        InitializeComponent()

        'Set the Mode of Drawing as Owner Drawn
        TabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed

        'Add the Handler to draw the Image on Tab Pages
        AddHandler TabControl1.DrawItem, AddressOf TabControl1_DrawItem
    End Sub

    Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs)
        Try
            'Close Image to draw
            Dim img As Image = New Bitmap(Application.StartupPath & "\img\close.png")
            Dim r As Rectangle = e.Bounds

            r = Me.TabControl1.GetTabRect(e.Index)
            r.Offset(2, 2)
            Dim TitleBrush As Brush = New SolidBrush(Color.Black)
            Dim f As Font = Me.Font
            Dim title As String = Me.TabControl1.TabPages(e.Index).Text
            e.Graphics.DrawString(title, f, TitleBrush, New PointF(r.X, r.Y))
            e.Graphics.DrawImage(img, New Point(r.X + (Me.TabControl1.GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y))

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub TabControl1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseClick
        Dim tc As TabControl = CType(sender, TabControl)
        Dim p As Point = e.Location
        Dim _tabWidth As Integer

        _tabWidth = Me.TabControl1.GetTabRect(tc.SelectedIndex).Width - (_imgHitArea.X)
        Dim r As Rectangle = Me.TabControl1.GetTabRect(tc.SelectedIndex)
        r.Offset(_tabWidth, _imgHitArea.Y)
        r.Width = 16
        r.Height = 16
        If r.Contains(p) Then
            Dim TabP As TabPage = DirectCast(tc.TabPages.Item(tc.SelectedIndex), TabPage)
            tc.TabPages.Remove(TabP)
        End If
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        TabControl1.Controls.Remove(agores)
        TabControl1.Controls.Remove(epixeirisi)
        TabControl1.Controls.Remove(pelates)
        TabControl1.Controls.Remove(poliseis)
        TabControl1.Controls.Remove(proionta)
        TabControl1.Controls.Remove(promitheutes)
        TabControl1.Controls.Remove(epilogiEpixeirisis)

        Dim categoryadapter As hard_oneDataSetTableAdapters.epixeirisi_listTableAdapter = New hard_oneDataSetTableAdapters.epixeirisi_listTableAdapter
        Dim categorytable As hard_oneDataSet.epixeirisi_listDataTable = New hard_oneDataSet.epixeirisi_listDataTable

        categoryadapter.Fill(categorytable)
        etairiesComboBox.DataSource = categorytable
        etairiesComboBox.DisplayMember = "idEpixeirisi"
        etairiesComboBox.ValueMember = "idEpixeirisi"

        TabControl1.TabPages.Add(epilogiEpixeirisis)
        TabControl1.SelectedTab = epilogiEpixeirisis

    End Sub


    Private Sub CloseTabToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseTabToolStripMenuItem.Click

        Me.TabControl1.TabPages.Remove(Me.TabControl1.SelectedTab)

    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()

    End Sub

    Private Sub cheakToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cheakToolStripMenuItem.Click
        MessageBox.Show("You have the last version!!!")
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        MessageBox.Show("Υπεύθυνοι για την συγγραφή και δημιουργία του Hardone είναι οι Νίκος Ανθιμίδης, Γρηγόρης Καγιάς, Αβραάμ Κουπτσίδης και Κυριάκος Παπαδόπουλος.")
    End Sub

    Private Sub vHelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles vHelpToolStripMenuItem.Click
        MessageBox.Show("Για περισσότερες πληροφορίες επισκεφθείτε στην διεύθυνση https://www.hardone.com")
    End Sub

    Private Sub epilogiEpixeirisiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles epilogiEpixeirisiToolStripMenuItem.Click
        TabControl1.TabPages.Add(epilogiEpixeirisis)
        TabControl1.SelectedTab = epilogiEpixeirisis
    End Sub

    Private Sub epilogiEpixButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles epilogiEpixButton.Click
        Try
            'Me.setKeep_etairia(etairiesComboBox.Text)'

            setaitaria(etairiesComboBox.Text)

            MessageBox.Show("Η εταιρία  " & keepetaira() & "  Επιλέχθηκε ")
        Catch ex As Exception

        End Try

    End Sub

    Private Sub epilogiAgorasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles epilogiAgorasToolStripMenuItem.Click
    End Sub

    Private Sub epilogiPelatiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles epilogiPelatiToolStripMenuItem.Click
        Dim T As New TabPage
        T.Text = "Πελάτες"
        Dim C As New PelatesControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Private Sub epilogiPolisisToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles epilogiPolisisToolStripMenuItem3.Click
        Dim T As New TabPage
        T.Text = "Πωλήσεις"
        Dim C As New PoliseisControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Private Sub epilogiProiontaToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles epilogiProiontaToolStripMenuItem1.Click
        Dim T As New TabPage
        T.Text = "Προϊόντα"
        Dim C As New SelectProiontaControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Private Sub epilogiPromitheutesToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles epilogiPromitheutesToolStripMenuItem2.Click
        Dim T As New TabPage
        T.Text = "Προμηθευτές"
        Dim C As New SelectPromitheutesControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Public Function TabPageOpen(ByRef frmName As String) As Boolean
        For Each page As TabPage In TabControl1.TabPages
            If page.Name = frmName Then
                Me.TabControl1.SelectedTab = page
                Return True
            End If
        Next page
        Return False
    End Function

    Private Sub epeksergasiaPelatiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles epeksergasiaPelatiToolStripMenuItem.Click
        Dim T As New TabPage
        T.Text = "Πελάτες"
        Dim C As New EditPelatesUserControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Private Sub dimiourgiaPelatiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dimiourgiaPelatiToolStripMenuItem.Click
        Dim T As New TabPage
        T.Text = "Πελάτες"
        Dim C As New CreatePelatesUserControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub


    Private Sub epeksergasiaPromitheutesToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles epeksergasiaPromitheutesToolStripMenuItem1.Click
        Dim T As New TabPage
        T.Text = "Προμηθευτές"
        Dim C As New PromitheutesControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Private Sub epeksergasiaProiontaToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles epeksergasiaProiontaToolStripMenuItem2.Click
        Dim T As New TabPage
        T.Text = "Προϊόντα"
        Dim C As New ProiontaControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Private Sub dimiourgiaPromitheutesToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dimiourgiaPromitheutesToolStripMenuItem1.Click       
        Dim T As New TabPage
        T.Text = "Προϊόντα"
        Dim C As New CreatePromitheutesUserControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Private Sub dimiourgiaAgorasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dimiourgiaAgorasToolStripMenuItem.Click
        Dim T As New TabPage
        T.Text = "Αγορές"
        Dim C As New AgoresControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Private Sub dimiourgiaPolisisToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dimiourgiaPolisisToolStripMenuItem2.Click
        Dim T As New TabPage
        T.Text = "Πωλήσεις"
        Dim C As New PoliseisControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Private Sub dimiourgiaEpixeirisiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dimiourgiaEpixeirisiToolStripMenuItem.Click
        Dim T As New TabPage
        T.Text = "Επιχείρηση"
        Dim C As New CreateEpixeirisiUserControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub

    Private Sub eisagwgiProiontaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eisagwgiProiontaToolStripMenuItem.Click
        Dim T As New TabPage
        T.Text = "Προϊόντα"
        Dim C As New CreateProiontaUserControl
        C.Parent = T
        T.Controls.Add(C)
        TabControl1.TabPages.Add(T)
        TabControl1.SelectedTab = T
    End Sub
End Class
